package com.cstp.config;

import com.cstp.exception.ServiceException;
import com.cstp.web.res.Resp;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 主要针对风控异常
 *
 * @author watts
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @SneakyThrows
    @ExceptionHandler(Exception.class)
    Resp<?> handleRiskException(Exception exception) {
        log.error(exception.getMessage(), exception);
        return Resp.fail("服务开小差了...");
    }

    @SneakyThrows
    @ExceptionHandler(ServiceException.class)
    Resp<?> handleRiskException(ServiceException exception) {
        log.error(exception.getMessage(), exception);
        return Resp.fail(exception.getCode(), exception.getMessage());
    }

}
